knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE, fig.height = 4, fig.width = 7)
library(terra)
library(oharac)
library(tidyverse)
library(here)
source(here('common_fxns.R'))With impact maps generated for all stressors, means calculated both unweighted and FV-weighted, we can add the impact layers to generate a comprehensive cumulative human impact map. This script aggregates by stressor group: fishing-related, land-based, ocean-based, and climate.
See scripts 2, 3a, and 3b for vulnerability mapping scripts, and scripts 4a-4d for impact calculation scripts.
Sum impacts across all stressor/vulnerability combos, by stressor group.
str_gp_df <- read_csv(here('_raw/stressor_vulnerability_lookup.csv'))imp1_fs <- list.files(here('_output/impact_maps/impact_maps_unweighted'),
pattern = 'mean',
full.names = TRUE)
imp1_stack <- rast(imp1_fs) %>%
setNames(str_remove_all(basename(imp1_fs), '.+unwt_|_x_.+|_mean.tif'))
ocean_a_rast <- rast(here('_spatial/ocean_area_mol.tif'))
unwt_outfile_stem <- here('_output/impact_maps/cumulative_maps/unweighted_group_chi_%s.tif')
str_gps <- str_gp_df$stressor_group %>% unique()
for(str_gp in str_gps) {
### str_gp <- str_gps[1]
unwt_outfile <- sprintf(unwt_outfile_stem, str_gp)
if(!file.exists(unwt_outfile)) {
str_vec <- str_gp_df %>%
filter(stressor_group == str_gp) %>%
.$stressor
gp_stack <- imp1_stack[[str_vec]]
### Calculate cumulative impacts for this group
gp_chi_unwt_raw <- sum(gp_stack, na.rm = TRUE)
gp_chi_unweighted <- gp_chi_unwt_raw %>%
mask(ocean_a_rast) %>%
setNames(sprintf('%s_chi_unwt', str_gp))
writeRaster(gp_chi_unweighted, unwt_outfile,
overwrite = TRUE)
}
}for(s in str_gps) {
### s <- str_gps[1]
f <- sprintf(unwt_outfile_stem, s)
r <- rast(f)
plot(log10(r), col = hcl.colors(50),
main = paste0('Log_10(', s, ' stressors), unweighted'),
axes = FALSE)
}Sum impacts across all stressor/vulnerability combos.
imp2_fs <- list.files(here('_output/impact_maps/impact_maps_fv_weighted'),
pattern = 'mean',
full.names = TRUE)
imp2_stack <- rast(imp2_fs) %>%
setNames(str_remove_all(basename(imp2_fs), '.+fvwt_|_x_.+|_mean.tif'))
fvwt_outfile_stem <- here('_output/impact_maps/cumulative_maps/fvweighted_group_chi_%s.tif')
str_gps <- str_gp_df$stressor_group %>% unique()
for(str_gp in str_gps) {
### str_gp <- str_gps[1]
fvwt_outfile <- sprintf(fvwt_outfile_stem, str_gp)
if(!file.exists(fvwt_outfile)) {
str_vec <- str_gp_df %>%
filter(stressor_group == str_gp) %>%
.$stressor
gp_stack <- imp2_stack[[str_detect(names(imp2_stack), smash2or(str_vec))]]
### Calculate cumulative impacts for this group
gp_chi_fvwt_raw <- sum(gp_stack, na.rm = TRUE)
gp_chi_fvweighted <- gp_chi_fvwt_raw %>%
mask(ocean_a_rast) %>%
setNames(sprintf('%s_chi_fvwt', str_gp))
writeRaster(gp_chi_fvweighted, fvwt_outfile,
overwrite = TRUE)
}
}for(s in str_gps) {
### s <- str_gps[1]
f <- sprintf(fvwt_outfile_stem, s)
r <- rast(f)
plot(log10(r), col = hcl.colors(50),
main = paste0('Log_10(', s, ' stressors), FV-weighted'),
axes = FALSE)
}Difference in CHI calculated from FV-weighted vulnerability relative to unweighted vulnerability (using only spp included in functional entities): \[\frac{CHI_{FV} - CHI_{unweighted}}{CHI_{unweighted}} \times 100\%\]
for(s in str_gps) {
### s <- str_gps[1]
f1 <- sprintf(fvwt_outfile_stem, s)
r1 <- rast(f1)
f2 <- sprintf(unwt_outfile_stem, s)
r2 <- rast(f2)
r <- (r1 - r2) / r2
plot(r, col = hcl.colors(50),
main = paste0('Difference: FV-weighted vs unweighted ', s, ' stressors'),
axes = FALSE)
}